import allure
from selenium.webdriver.common.by import By

from key_word.key_word import KeyWord
from locator.goods import page_stock_library_iframe, page_goods_page_save_btn


# 素材库
class Library(KeyWord):
    # 添加素材库
    def add_material(self, pages):
        with allure.step("选择规格图片"):
            self.change_into_iframe(*page_stock_library_iframe)  # 切换到素材库iframe
            for page_type, page_content in pages.items():  # 循环添加图片
                page_goods_page_type = [By.XPATH, f"//a[text()='{page_type}']"]
                self.click_el_until_visibility(*page_goods_page_type)  # 选择图片类型
                for page in page_content:  # 循环选择多张图片
                    page_goods_page_content = [By.XPATH, f"//p[text()='{page}']/..//figure"]
                    self.click_el_until_visibility(*page_goods_page_content)  # 选择图片
            self.click_el_until_visibility(*page_goods_page_save_btn)  # 点击确认
